#-------------------------------------------------------------------
# The contents of this file are placed in the public domain. Feel
# free to make use of it in any way you like.
#-------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED( VERSION 2.6.0 )
if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

# Use relative paths
# This is mostly to reduce path size for command-line limits on windows
if(WIN32)
  # This seems to break Xcode projects so definitely don't enable on Apple builds
  set(CMAKE_USE_RELATIVE_PATHS true)
  set(CMAKE_SUPPRESS_REGENERATION true)
endif()

if(WIN32)
	set(CMAKE_MODULE_PATH "$ENV{OGRE_HOME}/CMake/;${CMAKE_MODULE_PATH}")
endif(WIN32)
 
if(UNIX)
	set(CMAKE_MODULE_PATH "/usr/local/lib/OGRE/cmake/;/usr/lib/OGRE/cmake/;${CMAKE_MODULE_PATH}")
endif(UNIX)

if (CMAKE_BUILD_TYPE STREQUAL "")
  # CMake defaults to leaving CMAKE_BUILD_TYPE empty. This screws up
  # differentiation between debug and release builds.
  set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "Choose the type of build, options are: None (CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif ()

set(PROJECT_NAME OgreMeshTool)
PROJECT( ${PROJECT_NAME} )
add_definitions(-DPROJECT_NAME="${PROJECT_NAME}")


SET(VERSION_MAJOR  "1")
SET(VERSION_MINOR  "3")
SET(VERSION_PATCH  "1")
SET(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/src/OgreMeshToolVersionTemplate.h.in ${CMAKE_SOURCE_DIR}/src/OgreMeshToolVersion.h)

message(STATUS "configuring ${PROJECT_NAME} version ${VERSION_STRING} ...")

FIND_PACKAGE(wxWidgets COMPONENTS core base aui adv REQUIRED)
include( "${wxWidgets_USE_FILE}" )


if(WIN32)
 set(OGRE_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/dependencies/include/Ogre")
 set(OGRE_LIBRARIES    "${CMAKE_SOURCE_DIR}/dependencies/lib/Ogre/OgreMain.lib")
 set(OGRE_FOUND TRUE)

 set(assimp_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/dependencies/include/assimp")
 set(assimp_LIBRARIES    "${CMAKE_SOURCE_DIR}/dependencies/lib/assimp/assimp.lib")
 set(assimp_FOUND TRUE)
else()
 find_package(PkgConfig)

 # some linux distris are not working well on this, better use pkg-config ...
 #find_package (OGRE REQUIRED)

 PKG_CHECK_MODULES(OGRE   OGRE   REQUIRED)
 PKG_CHECK_MODULES(assimp assimp)
 
 # and some gtk things required for linux:
 PKG_CHECK_MODULES  (GTK gtk+-2.0 REQUIRED)
 PKG_CHECK_MODULES  (GTK_PIXBUF gdk-pixbuf-2.0 REQUIRED)
 include_directories(${GTK_INCLUDE_DIRS})
 include_directories(${GTK_PIXBUF_INCLUDE_DIRS})
endif ()

# add includes
include_directories(${OGRE_INCLUDE_DIRS})

if(assimp_FOUND)
 message(STATUS "* Open Asset Importer (AssImp) [http://assimp.sourceforge.net] found, importing functions enabled.")
 include_directories(${assimp_INCLUDE_DIRS})
 add_definitions(-DUSE_ASSIMP)
else()
 message(STATUS "* Open Asset Importer (AssImp) [http://assimp.sourceforge.net] not found, importing functions disabled.")
endif()

# and boost
FIND_PACKAGE(Boost REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIB_DIR})

# dependencies done, add the sources
include_directories("${CMAKE_SOURCE_DIR}/src" )

set (SOURCES
	src/CmdSettings.h
	src/Constants.h
	src/Core/AnimationPanel.h
	src/Core/GridSettingsImpl.h
	src/Core/MovableText.h
	src/Core/Panels/AnimPosePanel.h
	src/Core/Panels/LightsPanel.h
	src/Core/Panels/MaterialsPanel.h
	src/Core/Panels/statpict.h
	src/Core/wxOgreMeshViewerMainFrame.h
	src/Core/wxOgreMeshViewerMainFrameImpl.h
	src/Core/wxOgreRenderWindow.h
	src/Core/wxOgreRenderWindowListener.h
	src/Core/wxResourceHelper.h
	src/main.cpp
	src/Core/AnimationPanel.cpp
	src/Core/GridSettingsImpl.cpp
	src/Core/MovableText.cpp
	src/Core/Panels/AnimPosePanel.cpp
	src/Core/Panels/LightsPanel.cpp
	src/Core/Panels/MaterialsPanel.cpp
	src/Core/Panels/statpict.cpp
	src/Core/wxOgreMeshViewerMainFrame.cpp
	src/Core/wxOgreMeshViewerMainFrameImpl.cpp
	src/Core/wxOgreRenderWindow.cpp
	src/Core/wxResourceHelper.cpp
	)

if(assimp_FOUND)
set (SOURCES ${SOURCES} 
	src/assimp/AssimpLoader.h
	src/assimp/AssimpLoader.cpp
	)
endif()

if(WIN32)
	# add icon
	set (SOURCES ${SOURCES} ${CMAKE_SOURCE_DIR}/src/resource.rc)
endif()

SET(RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/bin/")
SET(LIBRARY_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/")
SET(ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/lib/")
SET(EXECUTABLE_OUTPUT_PATH   ${RUNTIME_OUTPUT_DIRECTORY})
SET(LIBRARY_OUTPUT_PATH      ${RUNTIME_OUTPUT_DIRECTORY})

if(WIN32)
	ADD_EXECUTABLE(${PROJECT_NAME} WIN32 ${SOURCES})
else()
	ADD_EXECUTABLE(${PROJECT_NAME}       ${SOURCES})
endif()

TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${wxWidgets_LIBRARIES} )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${OGRE_LIBRARIES} )
if(assimp_FOUND)
 TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${assimp_LIBRARIES} )
endif()

set(INST_DEST ".")
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${INST_DEST})

if(WIN32)
	# add 3rd party files: Ogre, etc
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/assimp.dll DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/OgreMain.dll DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/plugins.cfg DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/Plugin_CgProgramManager.dll DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/Plugin_OctreeSceneManager.dll DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/Plugin_ParticleFX.dll DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/RenderSystem_Direct3D9.dll DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/RenderSystem_GL.dll DESTINATION ${INST_DEST})

	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/OgreMeshUpgrader.exe DESTINATION ${INST_DEST})
	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/OgreXMLConverter.exe DESTINATION ${INST_DEST})

	install(FILES ${CMAKE_SOURCE_DIR}/bin/Release/cg.dll DESTINATION ${INST_DEST})
	
else()
	#linux
	install(FILES ${CMAKE_SOURCE_DIR}/bin/plugins.cfg DESTINATION ${INST_DEST})
endif()
install(FILES ${CMAKE_SOURCE_DIR}/bin/OgreMeshToolResources.zip DESTINATION ${INST_DEST})

# and CPack
# cpack
set(CPACK_PACKAGE_DESCRIPTION "${PROJECT_NAME}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Ogre Mesh Tool is for viewing OGRE mesh files. ")
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "wxwidgets ogre assimp")
set(CPACK_PACKAGE_CONTACT "http://code.google.com/p/ogre-meshtool/")
set(CPACK_PACKAGE_VENDOR "http://code.google.com/p/ogre-meshtool/")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
#SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ReadMe.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECT_NAME}")

#SET(CPACK_SOURCE_IGNORE_FILES "~$;/.hg/;/build/")
set(CPACK_SOURCE_IGNORE_FILES "/build*/;/bin/;/dependencies*;OgreMeshToolVersion\\\\.h;/CVS/;/\\\\.svn/;/\\\\.bzr/;/\\\\.hg/;/\\\\.git/;\\\\.swp$;\\\\.#;/#")

SET(CPACK_SOURCE_INSTALLED_DIRECTORIES "${CMAKE_SOURCE_DIR};/")

SET(CPACK_GENERATOR ZIP)
IF(UNIX)
 SET(CPACK_GENERATOR ${CPACK_GENERATOR};STGZ;TGZ;DEB;RPM)
 SET(CPACK_SOURCE_GENERATOR ${CPACK_SOURCE_GENERATOR};TGZ)
ENDIF(UNIX)
IF(MSVC)
 SET(CPACK_GENERATOR ${CPACK_GENERATOR};NSIS)
 SET(CPACK_SOURCE_GENERATOR ${CPACK_SOURCE_GENERATOR};ZIP)
ENDIF(MSVC)
IF(APPLE)
 SET(CPACK_GENERATOR ${CPACK_GENERATOR};PackageMaker)
 SET(CPACK_SOURCE_GENERATOR ${CPACK_SOURCE_GENERATOR};ZIP)
ENDIF(APPLE)
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}-${CPACK_PACKAGE_VERSION_MINOR}-${CPACK_PACKAGE_VERSION_PATCH}-${CMAKE_SYSTEM_PROCESSOR}")

#SET(CPACK_SOURCE_OUTPUT_CONFIG_FILE "/home/erin/mydroid/external/obexpushd-0.7-source/CPackSourceConfig.cmake")
#SET(CPACK_SOURCE_PACKAGE_FILE_NAME "obexpushd-0.7-source")
#SET(CPACK_SOURCE_TBZ2 "")
#SET(CPACK_SOURCE_TGZ "")
#SET(CPACK_SOURCE_TOPLEVEL_TAG "x86_64-linux-gnu-Source")
#SET(CPACK_SOURCE_TZ "")
#SET(CPACK_SOURCE_ZIP "")
#SET(CPACK_SOURCE_STRIP_FILES "")

# some NSIS stuff
IF(WIN32 AND NOT UNIX)
  # There is a bug in NSI that does not handle full unix paths properly. Make
  # sure there is at least one set of four (4) backlasshes.
  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  SET(CPACK_NSIS_HELP_LINK "http:\\\\\\\\http://code.google.com/p/ogre-meshtool/")
  SET(CPACK_NSIS_URL_INFO_ABOUT "http:\\\\\\\\http://code.google.com/p/ogre-meshtool/")
  SET(CPACK_NSIS_CONTACT "thomas@rigsofrods.com")
  SET(CPACK_NSIS_MODIFY_PATH OFF)
  #SET(CPACK_NSIS_MUI_FINISHPAGE_RUN "${PROJECT_NAME}.exe")
  #SET(CPACK_PACKAGE_ICON "${CMake_SOURCE_DIR}/Utilities/Release\\\\InstallIcon.bmp")
  
  set(CPACK_NSIS_MENU_LINKS "${PROJECT_NAME}.exe" "${PROJECT_NAME}")
  #set(CPACK_PACKAGE_EXECUTABLES "${PROJECT_NAME}.exe" "${PROJECT_NAME}")
  
  SET(CPACK_NSIS_INSTALLED_ICON_NAME "${PROJECT_NAME}.exe")
ELSE(WIN32 AND NOT UNIX)
  #SET(CPACK_STRIP_FILES "bin/MyExecutable")
ENDIF(WIN32 AND NOT UNIX)
#SET(CPACK_PACKAGE_EXECUTABLES "MyExecutable" "My Executable")
INCLUDE(CPack)
